草庐IT

public-method

全部标签

c# - 数字必杀技 : Where does a callvirt of a non-existent method end up?

我在其基类中标记为抽象的库类上调用属性集访问器。现在在运行时我force应用程序针对另一个版本的库运行,其中类仅实现基类的底层接口(interface),但不是从它派生的。有趣的是,.NET将运行代码,但设置该属性没有任何效果。幕后发生了什么?违规代码:MyDbParameterparam=newMyDbParameter();param.ParameterName="p";Console.Out.WriteLine("ParameterName:"+param.ParameterName);库2.0(已编译)publicsealedclassMyDbParameter:System.

c# - 使用 DTO 而不是在公共(public)程序集中共享对实体的引用是否有好处?

我正试图为一个让我抓狂了很长时间的问题找到一个明确的最终答案。通常表示BLL应包含业务逻辑和业务对象(BO),并具有对DAL的引用。另一方面,DAL不能引用BLL,因此它不能接受BO作为参数,或返回BO作为返回值。这个问题最传统的答案是:a)接受简单参数,返回(最好是Typed)DataSets和DataTables返回数据:命名空间DAL{公共(public)课联系方式公共(public)数据表GetContacts(){...}公共(public)UpdateContacts(DataTable联系人){...}b)第二个最推荐的解决方案是定义临时的、可序列化的数据传输对象(DTO

c# - 犀牛模拟 : How to stub a generic method to catch an anonymous type?

我们需要stub一个通用方法,该方法将使用匿名类型作为类型参数来调用。考虑:interfaceIProgressReporter{TReport(TprogressUpdater);}//Unittestarrange:FuncreturnArg=(x=>x);//wewishtoreturntheargument_reporter.Stub(x=>x.Report(null).IgnoreArguments().Do(returnArg);如果在被测方法中对.Report()的实际调用是使用对象作为类型参数完成的,那么这将起作用,但实际上,调用该方法时使用的T是匿名类型。此类型在被测

c# - 在类内部时,调用它的私有(private)成员还是公共(public)属性更好?

这个问题在这里已经有了答案:ShouldyouaccessavariablewithinthesameclassviaaProperty?(6个答案)关闭9年前。这是我在代码中一直纠结的问题。假设我们有以下代码:publicclassMyClass{privatestring_myVariable;publicstringMyVariable{get{return_myVariable;}set{_myVariable=value;}}publicvoidMyMethod(){stringusingPrivateMember=_myVariable;//methodAstringusi

c# - 通过安装程序设置模拟属性会导致 'Expression is not a method invocation'

我有下面的代码,其中我的Mock接口(interface)有一个Recorder属性,它是一个类。然后我尝试在该类上设置一个属性,但我得到了一个Expressionisnotamethodinvocation错误。你能帮忙吗?错误是在运行时尝试设置枚举属性时出现的。它会抛出一个带有以下堆栈跟踪的ArgumentException:atMoq.ExpressionExtensions.ToMethodCall(LambdaExpressionexpression)atMoq.Mock.c__DisplayClass1c`2.b__1b()atMoq.PexProtector.Invoke

C# 错误 : The call is ambiguous between the following methods or properties. 运算符重载

我在名为Dinero的命名空间中有2个带有重载运算符的类,这些是2个类:第一个:namespaceDinero{classDollar{#regionAtributospublicDoublecant;#endregion#regionConstructorespublicDollar(){this.cant=0;}publicDollar(Doubleamount){this.cant=amount;}#endregion#regionSobrecargadeOperadorespublicstaticDollaroperator+(Euroeu,Dollardol){Dollard

c# - 如何: Use async methods with LINQ custom extension method

我有一个LINQ自定义扩展方法:publicstaticIEnumerableDistinctBy(thisIEnumerableitems,Funcproperty){returnitems.GroupBy(property).Select(x=>x.First());}我是这样使用它的:varspc=context.pcs.DistinctBy(w=>w.province).Select(w=>new{abc=w}).ToList();但问题是我不想要ToList()我想要这样的东西varspc=awaitcontext.pcs.DistinctBy(w=>w.province).

c# - 如何从 *.dll 中检索所有公共(public)方法

我有一个用C#编写的*.dll,我需要获取该*.dll中包含的所有公共(public)方法或类的列表。有什么方法可以用C#以编程方式完成吗? 最佳答案 是使用Assembly.GetTypes提取所有类型,然后对每种类型使用反射来迭代公共(public)方法。Assemblya=Assembly.LoadWithPartialName("...");Type[]types=a.GetTypes();foreach(Typetypeintypes){if(!type.IsPublic){continue;}MemberInfo[]me

c# - T 必须是具有公共(public)无参数构造函数的非抽象类型,以便将其用作泛型类型或方法中的参数 'TModel'

我尝试在SO中搜索答案并偶然发现了类似的问题,但我无法使用它们来解决我的问题,因此请尽量不要将其标记为重复。让我们继续进行真正的交易:我有一个用于标准化EntityFramework数据库优先模型的通用库。这些是我创建的通用类:publicabstractclassGenericLookupModel:IActive,ICreated,IModified,IIdentity,IStringValue{publicboolis_active{get;set;}publicstringvalue{get;set;}publicstringdescription{get;set;}publi

C# 或 VB.NET - 迭代所有公共(public)枚举

我们的源代码中有一个通用组件,它包含一个非常大的应用程序的所有枚举(大约300个!)。有没有什么方法可以使用C#或VB.NET遍历所有这些对象以便对每个对象执行一个操作?问题Howtoiterateall“publicstring”propertiesina.netclass几乎是相关的,但我正在处理的枚举是多种类型的混合 最佳答案 类似的东西?varquery=Assembly.GetExecutingAssembly().GetTypes().Where(t=>t.IsEnum&&t.IsPublic);foreach(Type