本文整理汇总了C#中SimpleType类的典型用法代码示例。如果您正苦于以下问题:C# SimpleType类的具体用法?C# SimpleType怎么用?C# SimpleType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleType类属于命名空间,在下文中一共展示了SimpleType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitMethodDeclaration
public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration)
{
Guard.AgainstNullArgument("methodDeclaration", methodDeclaration);
IEnumerable<ParameterDeclaration> parameters = methodDeclaration
.GetChildrenByRole(Roles.Parameter)
.Select(x => (ParameterDeclaration)x.Clone());
var isVoid = false;
var isAsync = methodDeclaration.Modifiers.HasFlag(Modifiers.Async);
AstType returnType = methodDeclaration.GetChildByRole(Roles.Type).Clone();
var type = returnType as PrimitiveType;
if (type != null)
{
isVoid = string.Compare(
type.Keyword, "void", StringComparison.OrdinalIgnoreCase) == 0;
}
var methodType = new SimpleType(Identifier.Create(isVoid ? "Action" : "Func"));
IEnumerable<AstType> types = parameters.Select(
x => x.GetChildByRole(Roles.Type).Clone());
methodType
.TypeArguments
.AddRange(types);
if (!isVoid)
{
methodType.TypeArguments.Add(returnType);
}
var methodName = GetIdentifierName(methodDeclaration);
var methodBody = methodDeclaration
.GetChildrenByRole(Roles.Body)
.FirstOrDefault();
if (methodBody == null)
{
throw new NullReferenceException(string.Format("Method '{0}' has no method body", methodName));
}
methodBody = (BlockStatement)methodBody.Clone();
var prototype = new VariableDeclarationStatement { Type = methodType };
prototype.Variables.Add(new VariableInitializer(methodName));
var anonymousMethod = new AnonymousMethodExpression(methodBody, parameters) { IsAsync = isAsync };
var expression = new ExpressionStatement
{
Expression = new AssignmentExpression(
new IdentifierExpression(methodName),
anonymousMethod)
};
_methods.Add(new MethodVisitorResult
{
MethodDefinition = methodDeclaration,
MethodPrototype = prototype,
MethodExpression = expression
});
}
示例2: GetOriginalQueryableType
public override SimpleType GetOriginalQueryableType()
{
var memberExp = GetTranslatedParameterOrMember(GetParameter("x"));
var mappedItem = new SimpleType(MappedItemType, memberExp.Type);
mappedItem.Includes.AddRange(Includes);
return mappedItem;
}
示例3: Main
public static void Main (string[] args) {
var a = new SimpleType(0);
Console.WriteLine("a = {0}", a.Value);
Increment(ref a.Value);
Console.WriteLine("a = {0}", a.Value);
}
示例4: AddInclude
private void AddInclude(SimpleType source, MemberExpression memberSelector, LambdaExpression collectionInclude)
{
var members = source.GetAllMembers();
if (members.Count > 0 && memberSelector.GetDepth() > 1)
{
var innermostMember = ExpressionUtil.GetInnermostMemberExpression(memberSelector);
foreach (var kvp in members)
{
if (kvp.Key == innermostMember.Member)
{
AddInclude(kvp.Value, ExpressionUtil.ReplaceInnermostMemberExpressionWithParameter(memberSelector) as MemberExpression, collectionInclude);
return;
}
}
}
else
{
var parameter = ExpressionUtil.GetParameterExpression(memberSelector);
if (collectionInclude != null)
{
source.Includes.Add(IncludeDirectiveUtil.GetIncludeInCollectionDirective(memberSelector, collectionInclude));
}
else
{
source.Includes.Add(IncludeDirectiveUtil.GetIncludeDirective(memberSelector));
}
}
}
示例5: GenericWithArrayVariableDeclarationStatementTest1
public void GenericWithArrayVariableDeclarationStatementTest1()
{
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("G<int>[] a;");
AstType type = new SimpleType("G") {
TypeArguments = { new PrimitiveType("int") }
}.MakeArrayType();
Assert.IsTrue(new VariableDeclarationStatement(type, "a").IsMatch(lvd));
}
示例6: SimpleFieldGenerator
public SimpleFieldGenerator(FieldInfo fld)
: base(fld)
{
_primitive = fld.DeclaringType.ParentConfig.ResolveName<SimpleType>(
fld.DeclaringType, ((SimpleTypeRef) fld).TypeName
);
_generator = new SimpleTypeGenerator(_primitive);
}
示例7: GetActions
static IEnumerable<CodeAction> GetActions(RefactoringContext context, SimpleType node)
{
var resolveResult = context.Resolve(node) as UnknownIdentifierResolveResult;
if (resolveResult == null)
yield break;
yield return new CodeAction(context.TranslateString("Create delegate"), script => {
script.CreateNewType(CreateType(context, node));
}, node);
}
示例8: the_same_graph_written_on_the_same_stream_is_not_detected_as_a_circular_reference
public void the_same_graph_written_on_the_same_stream_is_not_detected_as_a_circular_reference()
{
var graph = new SimpleType();
using(var writer = CreateWriter())
{
writer.Write(graph);
writer.Write(graph);
}
}
示例9: ComplexGenericVariableDeclarationStatementTest
public void ComplexGenericVariableDeclarationStatementTest()
{
VariableDeclarationStatement lvd = ParseUtilCSharp.ParseStatement<VariableDeclarationStatement>("Generic<Namespace.Printable, G<Printable[]> > where = new Generic<Namespace.Printable, G<Printable[]>>();");
AstType type = new SimpleType("Generic") {
TypeArguments = {
new MemberType { Target = new SimpleType("Namespace"), MemberName = "Printable" },
new SimpleType("G") { TypeArguments = { new SimpleType("Printable").MakeArrayType() } }
}};
Assert.IsTrue(new VariableDeclarationStatement(type, "where", new ObjectCreateExpression { Type = type.Clone() }).IsMatch(lvd));
}
示例10: CreateType
static DelegateDeclaration CreateType(RefactoringContext context, SimpleType simpleType)
{
var result = new DelegateDeclaration() {
Name = simpleType.Identifier,
Modifiers = ((EntityDeclaration)simpleType.Parent).Modifiers,
ReturnType = new PrimitiveType("void"),
Parameters = {
new ParameterDeclaration(new PrimitiveType("object"), "sender"),
new ParameterDeclaration(context.CreateShortType("System", "EventArgs"), "e")
}
};
return result;
}
示例11: AddEntity
public void AddEntity()
{
// Setup
var file = GetXmlFile(nameof(AddEntity));
var set = new XmlSet<SimpleType>(file);
var simpleType = new SimpleType();
// Execute
set.Add(simpleType);
// Assert
Assert.AreSame(simpleType, set.First());
Assert.AreEqual(1, set.Count);
}
示例12: ConvertToType
AstType ConvertToType (MemberName memberName)
{
AstType result;
if (memberName.Left != null) {
result = new MemberType () { MemberName = memberName.Name };
result.AddChild (ConvertToType (memberName.Left), MemberType.TargetRole);
} else {
result = new SimpleType () { Identifier = memberName.Name };
}
if (memberName.TypeArguments != null && !memberName.TypeArguments.IsEmpty) {
foreach (var arg in memberName.TypeArguments.Args) {
result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument);
}
}
return result;
}
示例13: CreateClassFromType
static TypeDeclaration CreateClassFromType(RefactoringContext context, SimpleType simpleType)
{
TypeDeclaration result;
string className = simpleType.Identifier;
if (simpleType.Parent is Attribute) {
if (!className.EndsWith("Attribute"))
className += "Attribute";
}
result = new TypeDeclaration() { Name = className };
var entity = simpleType.GetParent<EntityDeclaration>();
if (entity != null)
result.Modifiers |= entity.Modifiers & ~Modifiers.Internal;
return result;
}
示例14: graphs_which_contain_circular_references_are_not_supported
public void graphs_which_contain_circular_references_are_not_supported()
{
var graph = new SimpleType();
// Root to self.
graph.Value = graph;
Assert.Throws<SerializationException>(() => Write(graph));
// Descendent to root.
graph.Value = new SimpleType { Value = graph };
Assert.Throws<SerializationException>(() => Write(graph));
// Descendent to self.
graph.Value = new SimpleType();
graph.Value.Value = graph.Value;
Assert.Throws<SerializationException>(() => Write(graph));
// Descendent to parent.
graph.Value = new SimpleType { Value = graph.Value };
Assert.Throws<SerializationException>(() => Write(graph));
}
示例15: ConvertToTypeReference
public static AstType ConvertToTypeReference (this MonoDevelop.Projects.Dom.IReturnType returnType)
{
string primitiveType;
if (TypeTable.TryGetValue (returnType.DecoratedFullName, out primitiveType))
return new PrimitiveType (primitiveType);
AstType result = null;
if (!string.IsNullOrEmpty (returnType.Namespace))
result = new SimpleType (returnType.Namespace);
foreach (var part in returnType.Parts) {
if (result == null) {
var st = new SimpleType (part.Name);
foreach (var type in part.GenericArguments.Select (ga => ConvertToTypeReference (ga)))
st.AddChild (type, SimpleType.Roles.TypeArgument);
result = st;
} else {
var mt = new ICSharpCode.NRefactory.CSharp.MemberType () {
Target = result,
MemberName = part.Name
};
foreach (var type in part.GenericArguments.Select (ga => ConvertToTypeReference (ga)))
mt.AddChild (type, SimpleType.Roles.TypeArgument);
result = mt;
}
}
/*
List<TypeReference> genericTypes = new List<TypeReference> ();
foreach (MonoDevelop.Projects.Dom.IReturnType genericType in returnType.GenericArguments) {
genericTypes.Add (ConvertToTypeReference (genericType));
}
TypeReference result = new AstType (returnType.FullName, genericTypes);
result.IsKeyword = true;
result.PointerNestingLevel = returnType.PointerNestingLevel;
if (returnType.ArrayDimensions > 0) {
int[] rankSpecfier = new int[returnType.ArrayDimensions];
for (int i = 0; i < returnType.ArrayDimensions; i++) {
rankSpecfier[i] = returnType.GetDimension (i);
}
result.RankSpecifier = rankSpecfier;
}*/
return result;
}